package basic_1008;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		Scanner scanner=new Scanner(System.in);
		
		int N=scanner.nextInt();
		
		Map<Character, Integer> awin=new HashMap<Character, Integer>();
		Map<Character, Integer> bwin=new HashMap<Character, Integer>();
		int equal=0;
		
		awin.put('J', 0);
		awin.put('B', 0);
		awin.put('C', 0);
		
		bwin.put('J', 0);
		bwin.put('B', 0);
		bwin.put('C', 0);
		
		for(int i=0;i<N;i++) {
			char a=scanner.next().trim().charAt(0);
			char b=scanner.next().trim().charAt(0);
			
			int re=compare(a, b);
			if(re==0) {
				equal++;
			}else if(re>0) {
				awin.put(a, awin.get(a)+1);
			}else {
				bwin.put(b, bwin.get(b)+1);
			}
		}
		
		scanner.close();
		
		int aWinNum=awin.get('J')+awin.get('B')+awin.get('C');
		int bWinNum=bwin.get('J')+bwin.get('B')+bwin.get('C');
		System.out.println(aWinNum+" "+equal+" "+bWinNum);
		System.out.println(bWinNum+" "+equal+" "+aWinNum);
		
		List<Entry<Character, Integer>> aList=new ArrayList<Entry<Character, Integer>>();
		aList.addAll(awin.entrySet());
		List<Entry<Character, Integer>> bList=new ArrayList<Entry<Character, Integer>>();
		bList.addAll(bwin.entrySet());
		
		Comparator<Entry<Character, Integer>> comparator=new Comparator<Map.Entry<Character,Integer>>() {
			@Override
			public int compare(Entry<Character, Integer> o1, Entry<Character, Integer> o2) {
				if(o1.getValue()>o2.getValue()) {
					return -1;
				}else if(o1.getValue()<o2.getValue()) {
					return 1;
				}else {
					if(o1.getKey()>o2.getKey()) {
						return 1;
					}else if(o1.getKey()<o2.getKey()) {
						return -1;
					}
				}
				return 0;
			}
		};
		
		Collections.sort(aList, comparator);
		Collections.sort(bList, comparator);
		
		System.out.println(aList.get(0).getKey()+" "+bList.get(0).getKey());
	}
	
	static int compare(char A,char B) {
		if(A==B) {
			return 0;
		}else if(A=='J'&&B=='C'){
			return -1;
		}else if(A=='J'&&B=='B'){
			return 1;
		}else if(A=='C'&&B=='B'){
			return -1;
		}else if(A=='C'&&B=='J'){
			return 1;
		}else if(A=='B'&&B=='C'){
			return 1;
		}else if(A=='B'&&B=='J'){
			return -1;
		}
		return -2;
	}
}
